package com.example.myapplication.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.example.myapplication.Bean.User;
import com.example.myapplication.R;

import java.util.List;

public class ContactAdapter extends ArrayAdapter<User> {

    int resourceid ;
    public ContactAdapter(@NonNull Context context, int resource, @NonNull List<User> objects) {
        super(context, resource, objects);

        resourceid = resource;   //resourceid 接住  resource   this.resourceid=resource ;
    }

    @Override
    public View getView(int position , View convertView , ViewGroup parent){
        View view =convertView ;
        if ( view ==null){
            view = LayoutInflater.from(getContext()).inflate(resourceid, null);

        }
        ImageView contacimg =view .findViewById(R.id.contactimg);
        TextView contacname =view.findViewById(R.id.contactname);
        User user =getItem(position) ;
        contacimg.setImageResource(user.getUserimg());//接住数据并且传入
        contacname.setText(user.getName());
        return view ; /*返回*/
    }
}
